import "../util/rem";
import axios from "axios";
import doctor from './js/doctor/doctor' 
//  跳转地址
window.linkTo = function (href, callBack) {
  setTimeout(() => {
    // window.location.replace(href);
    location.hash = href
    $('body').empty();
    $('body').load('doctor/doctor.html')
    $(document).getScript(doctor,function(){
      console.log('load script')
    })
    console.log(3232)
    // location.href = href;
    callBack && callBack();
  }, 1000);
};


document.addEventListener("WeixinJSBridgeReady", function onBridgeReady() {
  // 通过下面这个API隐藏底部导航栏
  WeixinJSBridge.call("hideToolbar");
});

//  加载audio
let audio = `
    <audio id="btnAudio">
        <source src="./sound/button.wav" type="audio/wav" />
    </audio>
    <audio id="gobalAudio" autoplay loop>
        <source src="./sound/gobal.mp3" type="audio/mp3" />
    </audio>
`;

let body = $(document).find("body");
body.append(audio);

let globalAudio = $("#gobalAudio");

function initAudio() {
  globalAudio.get(0).play();
  document.addEventListener(
    "WeixinJSBridgeReady",
    function () {
      globalAudio.get(0).play();
    },
    false
  );
}
window.initAudio = initAudio;

initAudio();
window.globalClose = function () {
  globalAudio.get(0).pause();
};
$(".btnSoundOpen").on("click", function () {
  $("#btnAudio")[0].play();
});

const wxJsApiList = [
  // 需要使用的JS接口列表
  "updateAppMessageShareData",
  "updateTimelineShareData",
  // "onMenuShareTimeline", //朋友圈
  // "onMenuShareAppMessage", //微信朋友
  // "onMenuShareQQ", // QQ
  // "onMenuShareWeibo", //微博
  // "onMenuShareQZone" //QQ空间
];

let shareAppMessage = {
  title: "分享标题",
  desc: "分享描述",
  link: location.host,
  imgUrl: "分享的图片链接",
  success() {
    console.log("分享成功");
  },
};

wx.ready(function () {
  wx.checkJsApi({
    jsApiList: wxJsApiList,
    success(res) {
      console.log("checkJsApi: " + JSON.stringify(res));
    },
  });
  // wx.updateAppMessageShareData(shareAppMessage)
  // wx.updateTimelineShareData(shareAppMessage)
});

//
window.addEventListener('hashchange', event => console.log(333, event))

console.log(location.host + location.pathname);
axios({
  url: "/wx/getSignature",
  params: {
    url: encodeURIComponent(location.href.split("#")[0]),
  },
}).then((res) => {
  if (res.data.status == 200) {
    let result = res.data.result;
    // wx.config({
    //     debug: true,// 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
    //     appId: result.appId,// 必填，公众号的唯一标识
    //     timestamp: result.timestamp,// 必填，生成签名的时间戳
    //     nonceStr: result.nonceStr,// 必填，生成签名的随机串
    //     signature: result.signature,// 必填，签名
    //     jsApiList: wxJsApiList// 必填，需要使用的JS接口列表
    // });
  }
});

//  btn 按钮动画toogle
var timeStop = {};
function startFun() {
  let btnBuzz = $(".btn-buzz");
  btnBuzz.css("animation-play-state", "paused");
}
let timeoutBtn = {};
var changeImgSrcFun = function () {
  clearTimeout(timeoutBtn);
  let btnBuzz = $(".btn-buzz");
  btnBuzz.css("animation-play-state", "paused");
  timeoutBtn = setTimeout(() => {
    btnBuzz.css("animation-play-state", "running");
    execAn();
  }, 1000);
};
function execAn() {
  timeStop = setTimeout(() => {
    changeImgSrcFun();
  }, 3000);
}
execAn();
